home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 5.8 KB | 178 lines | [TEXT/CCL2] |
- (in-package :oou)
- ;(oou-provide :GWorld-view)
- (provide :GWorld-view)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; GWorld-view.Lisp
- ;;
- ;; Copyright © 1991 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; Provides a class of views based on GWorlds
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- ;(oou-dependencies :simple-view-ce
- ; :GWorld-u
- ; )
- (require :simple-view-ce)
- (require :GWorld-u)
-
- (export '(GWorld-view
- GW-alloc GW-realloc GW-free
- GWorld GW-depth GW-cTable GW-gDevice GW-init-flags GW-update-flags
- with-locked-GWorld-view
- ))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (eval-when (:compile-toplevel :load-toplevel :execute)
-
- (defmacro with-locked-GWorld-view (gw-view &body body)
- `(with-locked-GWorld (GWorld ,gw-view)
- ;(GWorld-set-origin ,gw-view (view-origin ,gw-view))
- ;this hack attempts to counteract the (#_SetOrigin 0 0) hack in focus-view
- ;currently this is addressed in a patch so it's not needed.
- ,@body))
-
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defclass GWorld-view (view)
-
- ((GWorld :accessor GWorld)
- (GW-depth :initarg :GW-depth
- :accessor GW-depth)
- (GW-cTable :initarg :GW-cTable
- :accessor GW-cTable)
- (GW-gDevice :initarg :GW-gDevice
- :accessor GW-gDevice)
- (GW-init-flags :initarg :GW-init-flags
- :accessor GW-init-flags)
- (GW-update-flags :initarg :GW-update-flags
- :accessor GW-update-flags)
- )
-
- (:default-initargs
- :GW-depth 8
- :GW-cTable (%null-ptr)
- :GW-gDevice (%null-ptr)
- :GW-init-flags 0
- :GW-update-flags 0
- ))
-
- ;(defmethod ccl::call-with-focused-view :around ((view GWorld-view) thunk &optional font-view)
- (defmethod call-with-focused-view :around ((view GWorld-view) thunk &optional font-view)
- (declare (ignore thunk font-view))
- (with-locked-GWorld-view view
- (call-next-method)))
-
- (defmethod wptr ((view GWorld-view)) (GWorld view))
-
- (defmethod view-clip-region ((view GWorld-view))
- nil
- ;(pref (wptr view) :CGrafPort.clipRgn)
- )
-
- (defmethod set-view-position :after ((view GWorld-view) h &optional v)
- (declare (ignore h v))
- (GW-realloc view))
-
- (defmethod set-view-size :after ((view GWorld-view) h &optional v)
- (declare (ignore h v))
- (GW-realloc view))
-
- (defmethod invalidate-corners ((view GWorld-view) topLeft bottomRight &optional erase-p)
- (declare (ignore v topLeft bottomRight erase-p)))
-
- (defmethod invalidate-view ((view GWorld-view) &optional erase-p)
- (declare (ignore view erase-p)))
-
- (defmethod install-view-in-window ((view GWorld-view) window)
- (declare (ignore view window))
- (error "method illegal for GWorld-views."))
-
- (defmethod remove-view-from-window ((view GWorld-view))
- (declare (ignore view))
- (error "method illegal for GWorld-views."))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defmethod GWorld-set-origin ((view GWorld-view) origin)
- (declare (dynamic-extent view origin))
- (setf (slot-value view 'view-origin) origin)
- (when (GWorld-allocated-p view)
- (rlet ((old-port_p :pointer)
- (old-gdh_p :pointer))
- (#_GetGWorld old-port_p old-gdh_p)
- (with-macptrs ((old-port (%get-ptr old-port_p))
- (old-gdh (%get-ptr old-gdh_p)))
- (if (eq view *current-view*)
- (#_SetOrigin :long origin)
- (without-interrupts
- (unwind-protect
- (progn
- (#_SetGWorld (GWorld view) (%null-ptr))
- (#_SetOrigin :long origin))
- (#_SetGWorld old-port old-gdh)))))))
- t)
-
- (defmethod GWorld-set-portRect ((view GWorld-view) r)
- (let ((tl (pref r :Rect.topLeft)))
- (declare (dynamic-extent tl))
- (setf (slot-value view 'view-position) tl)
- (setf (slot-value view 'view-size) (subtract-points (pref r :Rect.botRight) tl))
- (GW-realloc view))
- t)
-
- (defmethod GW-alloc ((view GWorld-view))
- (unless (GWorld-allocated-p view)
- (with-slots (GW-depth GW-cTable GW-gDevice GW-init-flags) view
- (rlet ((gWorld_p :pointer (%null-ptr))
- (r :Rect
- :topLeft (view-position view)
- :botRight (add-points (view-position view) (view-size view))))
- (without-interrupts
- (let ((ecode (#_NewGWorld gWorld_p GW-depth r GW-cTable GW-gDevice GW-init-flags)))
- (declare (dynamic-extent ecode))
- (unless (zerop ecode) (error "unable to allocate GWorld (~a)" ecode)))
- (setf (GWorld view) (%get-ptr gWorld_p)))
- (when (zerop GW-depth)
- (GWorld-set-origin view (view-position view)))))
- t))
-
- (defmethod GW-realloc ((view GWorld-view))
- (with-slots (GW-depth GW-cTable GW-gDevice GW-update-flags) view
- (rlet ((gWorld_p :pointer (GWorld view))
- (r :Rect
- :topLeft (view-position view)
- :botRight (add-points (view-position view) (view-size view))))
- (without-interrupts
- (let ((ecode (#_UpdateGWorld gWorld_p GW-depth r GW-cTable GW-gDevice GW-update-flags)))
- (declare (dynamic-extent ecode))
- (when (minusp ecode)
- (error "unable to update GWorld (~a)" ecode)))
- (setf (GWorld view) (%get-ptr gWorld_p)))
- (when (zerop GW-depth)
- (GWorld-set-origin view (view-position view)))))
- t)
-
- (defmethod GW-free ((view GWorld-view))
- (#_DisposeGWorld (GWorld view))
- (slot-makunbound view 'GWorld)
- t)
-
- (defmethod GWorld-allocated-p ((view GWorld-view))
- (slot-boundp view 'GWorld))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- #|
-
-
- example code can be found in kinesis-u
-
-
- |#